import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Dashboard from '../views/dashboard/Dashboard.vue'
import AppStore from '../views/apps/AppStore.vue'
import MyApps from '../views/apps/MyApps.vue'
import ProxyManagement from '../views/tools/ProxyManagement.vue'
import EmailManagement from '../views/tools/EmailManagement.vue'
import DiscordManagement from '../views/tools/DiscordManagement.vue'
import Balance from '../views/balance/Balance.vue'
import Recharge from '../views/balance/Recharge.vue'
import SystemInfo from '../views/SystemInfo.vue'

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: { requiresAuth: true },
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: Dashboard
      },
      {
        path: 'app-store',
        name: 'AppStore',
        component: AppStore
      },
      {
        path: 'proxy-management',
        name: 'ProxyManagement',
        component: ProxyManagement
      },
      {
        path: 'system-info',
        name: 'SystemInfo',
        component: SystemInfo
      },
      {
        path: 'email-management',
        name: 'EmailManagement',
        component: EmailManagement
      },
      {
        path: 'discord-management',
        name: 'DiscordManagement',
        component: DiscordManagement
      },
      {
        path: 'my-apps',
        name: 'MyApps',
        component: MyApps
      },
      {
        path: 'balance',
        name: 'Balance',
        component: Balance
      },
      {
        path: 'recharge',
        name: 'Recharge',
        component: Recharge
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 暂时注释掉登录验证，方便测试
  // const isAuthenticated = localStorage.getItem('token')
  
  // if (to.meta.requiresAuth && !isAuthenticated) {
  //   next('/login')
  // } else {
  //   next()
  // }
  next()
})

export default router
